<?php
header('Content-Type: application/json');
$keyword = $_GET['q'] ?? '';

$tagsFile = __DIR__.'/../data/tags.json';
$tagsData = json_decode(file_get_contents($tagsFile), true);

$results = [];
foreach ($tagsData as $imgName => $data) {
    if (array_search($keyword, $data['tags']) !== false) {
        $results[] = $imgName;
    }
}

echo json_encode($results);
?>